<template>
  <div class="popup-content">
    <CommonHeader type="白" leftIcon title="修改信息" />
    <div style="margin: 12px; border-radius: 4px">
      <van-field
        class="field1"
        label="备案者"
        center
        v-model="data.EnterprisePersonName"
        placeholder="请输入"
      />
      <van-field
        class="field1"
        label="统一社会信用代码"
        center
        v-model="data.EnterprisePersonCode"
        placeholder="请输入"
      />
      <van-field
        class="field1"
        label="负责人"
        center
        v-model="data.PrincipalName"
        placeholder="请输入"
      />
      <van-field
        class="field1"
        label="负责人身份证"
        center
        v-model="data.PrincipalIDCare"
        placeholder="请输入"
      />
      <van-field
        class="field1"
        label="联系人姓名"
        center
        v-model="data.LinkmanName"
        placeholder="请输入"
      />
      <van-field
        class="field1"
        label="联系人电话"
        center
        v-model="data.LinkmanPhone"
        placeholder="请输入"
      />
      <van-field
        class="field1"
        label="联系人邮箱"
        center
        v-model="data.LinkmanEmail"
        placeholder="请输入"
      />
      <van-field
        class="field1"
        label="联系人住所"
        center
        v-model="data.LinkmanDomicile"
        placeholder="请输入"
      />
    </div>

    <div style="margin: 16px; margin-top: 32px">
      <van-button
        type="primary"
        round
        block
        @click="onSubmit"
        color="linear-gradient(to right, #00BF87, #25F0A0)"
        >提交修改</van-button
      >
    </div>
  </div>
</template>
    
    <script setup>
import { ref, defineProps, defineEmits, watch } from "vue";
import { useRoute, useRouter } from "vue-router";
import uiUtil from "@/util/UiUtil.js";
const router = useRouter();
const route = useRoute();
const data = ref(route.query);

const back = () => {
  router.back();
};
const onSubmit = (value) => {
  submit();
};

const submit = () => {
  if (uiUtil.isObjNull(data.value.EnterprisePersonName)) {
    uiUtil.toastFail("备案者不能为空");
    return;
  }
  if (uiUtil.isObjNull(data.value.EnterprisePersonCode)) {
    uiUtil.toastFail("统一社会信用代码不能为空");
    return;
  }
  if (uiUtil.isObjNull(data.value.PrincipalName)) {
    uiUtil.toastFail("负责人姓名不能为空");
    return;
  }
  if (uiUtil.isObjNull(data.value.PrincipalIDCare)) {
    uiUtil.toastFail("负责人身份证不能为空");
    return;
  }
  if (data.value.PrincipalIDCare.length != 18) {
    uiUtil.toastFail("负责人身份证号码不足18位");
    return;
  }
  if (uiUtil.isObjNull(data.value.LinkmanName)) {
    uiUtil.toastFail("联系人姓名不能为空");
    return;
  }
  if (uiUtil.isObjNull(data.value.LinkmanPhone)) {
    uiUtil.toastFail("联系人电话不能为空");
    return;
  }
  if (uiUtil.isObjNull(data.value.LinkmanEmail)) {
    uiUtil.toastFail("联系人邮箱不能为空");
    return;
  }
  let params = {
    UserID: data.value.UserID,
    EnterprisePersonName: data.value.EnterprisePersonName,
    EnterprisePersonCode: data.value.EnterprisePersonCode,
    PrincipalName: data.value.PrincipalName,
    PrincipalIDCare: data.value.PrincipalIDCare,
    LinkmanName: data.value.LinkmanName,
    LinkmanPhone: data.value.LinkmanPhone,
    LinkmanEmail: data.value.LinkmanEmail,
    LinkmanDomicile: data.value.LinkmanDomicile,
  };
  uiUtil.http().postObj({
    url: uiUtil.urlPath.updateFilingEnterprisePerson,
    data: params,
    start: () => {
      uiUtil.toastLoading("加载中...");
    },
    succeed: (res) => {
      if (!res) {
        uiUtil.toastFail("网络超时");
        return;
      }
      if (!res || !res.code || 200 != res.code) {
        uiUtil.toastFail(res.msg);
        return;
      }
      uiUtil.toastSuccess(res.msg);
      back();
    },
    failed: (err) => {
      // debugger;
      uiUtil.toastFail("失败：" + err);
    },
    finish: (type) => {
      // debugger;
      console.log("finish=", type);
      // uiUtil.toastClose();
    },
  });
};
</script>
    
    <style scoped>
.popup-content {
  background: url("@/assets/img/main/all_bg.png") no-repeat;
  background-size: cover;
  height: 100%;
  display: flex;
  flex-direction: column;
  background-color: #f3f9f8;
  height: 100vh;
}
</style>